import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

public class TCpClient1 {
    private Socket socket=null;

    public TCpClient1(String tcpServe1,int port) throws IOException {
        socket=new Socket(tcpServe1,port);



    }
    public void start()
    {
        System.out.println("客户端开启");
        try(InputStream inputStream= socket.getInputStream(); OutputStream outputStream= socket.getOutputStream()) {
            Scanner scanner=new Scanner(System.in);
            while(true)
            {
                System.out.print('>');
                String request=scanner.next();
                if(request.equals("exit"))
                {
                    System.out.println("goodbye");
                    break;
                }

                PrintWriter printWriter=new PrintWriter(outputStream);
                printWriter.println(request);
                printWriter.flush();
                Scanner scanner1=new Scanner(inputStream);
                String response=scanner1.next();
                System.out.println(response);

            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    public static void main(String[] args) throws IOException {
        TCpClient1 cpClient1=new TCpClient1("192.168.43.90",10001);
        cpClient1.start();

    }
}
